What is @ts-graphviz/core?
@ts-graphviz/core is a TypeScript library for creating and manipulating Graphviz graphs. It provides a programmatic way to build and render graphs using the Graphviz DOT language.
What are @ts-graphviz/core's main functionalities?
Creating a Graph
This feature allows you to create a directed graph, add nodes, and create edges between them. The `toDot` method converts the graph to DOT format.
const { digraph } = require('@ts-graphviz/core');
const g = digraph('G');
g.node('A');
g.node('B');
g.edge(['A', 'B']);
console.log(g.toDot());
Subgraphs
This feature allows you to create subgraphs within a main graph. Subgraphs can be used to group nodes together.
const { digraph, subgraph } = require('@ts-graphviz/core');
const g = digraph('G');
const s = subgraph('cluster_0');
s.node('A');
s.node('B');
g.subgraph(s);
console.log(g.toDot());
Graph Attributes
This feature allows you to set attributes for the graph, such as the direction of the graph layout.
const { digraph } = require('@ts-graphviz/core');
const g = digraph('G', { rankdir: 'LR' });
g.node('A');
g.node('B');
g.edge(['A', 'B']);
console.log(g.toDot());
Other packages similar to @ts-graphviz/core
graphviz
The 'graphviz' package is a Node.js wrapper for the Graphviz command-line tool. It allows you to generate DOT files and render them to various formats like PNG, PDF, etc. Unlike @ts-graphviz/core, it relies on the Graphviz installation on your system.
viz.js
The 'viz.js' package is a JavaScript port of Graphviz that runs in the browser and Node.js. It allows you to render DOT files directly in the browser without needing a Graphviz installation. It is more focused on rendering rather than programmatic graph creation.
d3-graphviz
The 'd3-graphviz' package integrates Graphviz with D3.js, allowing you to create and manipulate graphs using D3's data-driven approach. It is more suitable for dynamic and interactive visualizations compared to @ts-graphviz/core.
@ts-graphviz/core
This package contains the core implementation of models and functions provided to users for the ts-graphviz library.
It is part of the ts-graphviz library, which is split into modular packages to improve maintainability, flexibility, and ease of use.
Features
- Graph, Node, and Edge model implementations
- High-level APIs for creating and manipulating DOT language elements
- Extensible design for custom implementations
Usage
Import the necessary classes and functions from the @ts-graphviz/core package:
import { Graph, Node, Edge } from '@ts-graphviz/core';
Use the imported items in your project to create and manipulate DOT language elements:
const graph = new Graph('G');
const nodeA = new Node('A', { label: 'Node A' });
const nodeB = new Node('B', { label: 'Node B' });
const edge = new Edge([nodeA, nodeB], { label: 'A -> B' });
graph.addNode(nodeA);
graph.addNode(nodeB);
graph.addEdge(edge);
console.log(graph.toDot());
For more examples and usage details, please refer to the ts-graphviz documentation.
Contributing
Contributions to the ts-graphviz project are welcome.
Please refer to the main ts-graphviz repository for guidelines on how to contribute.
License
This package is released under the MIT License.